<template>
  <div class="headers">
    <sequence></sequence>
    <div class="headersBody">
      <div class="headerTitler">
        <span class="dateTime">
          <!--<img src="../../assets/reast.png" alt="" style="height: 18px;margin-right: 10px;cursor: pointer" @click="reastData">-->
          {{ currentTimes }}
        </span>
      </div>
      <div class="headerTitle">
        <span>{{ name }}</span>
      </div>
      <div class="headerTitler">
        <!--<div class="tabs">
          <div class="tabItem" @click="clickItem(1)" :style="{opacity:selectedItem===1?1:0.5}">
            销售汇总
          </div>
          <div class="tabItem2" @click="clickItem(2)" :style="{opacity:selectedItem===2?1:0.5}">
            采购汇总
          </div>
        </div>-->
      </div>
    </div>
  </div>
</template>

<script>
import sequence from './sequence/index.vue'
import dayjs from 'dayjs'
import 'dayjs/locale/zh-cn' // 导入中文简体语言包
import weekOfYear from 'dayjs/plugin/weekOfYear'
import weekday from 'dayjs/plugin/weekday'

dayjs.extend(weekOfYear)
dayjs.extend(weekday)
dayjs.locale('zh-cn') // 设置语言为中文简体
export default {
  name: 'pageTop',
  components: { sequence },
  data () {
    return {
      currentTime: new Date(),
      currentTimes:'',
      selectedItem:1
    }
  },
  props: {
    name: {
      type: String,
      default () {
        return ''
      }
    },
    showTitleLeft: {
      type: Boolean,
      default () {
        return true
      }
    }
  },
  computed: {
    formattedTimeWithWeekday () {
      return dayjs(this.currentTime)
        .weekday(1) // 将星期一设置为每周的起始日期
        .format('YYYY-MM-DD HH:mm:ss dddd') // 格式化日期和时间
    }
  },
  mounted () {
    /*setInterval(() => {
      this.currentTime = new Date()
    }, 1000) // 每秒更新时间*/

    // 设置定时器每秒更新一次时间
    setInterval(() => {
      this.currentTimes = this.formatDate();
    }, 1000);
  },
  methods: {
    reastData(){
      this.$emit('reast')
    },
    formatDate() {
      const now = new Date();
      const year = now.getFullYear();
      const month = String(now.getMonth() + 1).padStart(2, '0'); // 月份从0开始，+1
      const day = String(now.getDate()).padStart(2, '0');
      const hours = String(now.getHours()).padStart(2, '0');
      const minutes = String(now.getMinutes()).padStart(2, '0');
      const seconds = String(now.getSeconds()).padStart(2, '0');
      // 获取星期几，0 是星期天，6 是星期六
      const weekDays = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
      const week = weekDays[now.getDay()];
      return `${year}-${month}-${day} ${hours}:${minutes}:${seconds} ${week}`;
    },
    clickItem(item){
      this.selectedItem = item
      this.$emit('selectItem',item)
    }
  }
}
</script>

<style lang="scss" scoped>
.headers {
  width: 100%;
  height: 116px;
  display: flex;
  position: relative;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: nowrap;
  flex-direction: row;
  align-content: flex-start;
}

.headersBody {
  position: relative;
  z-index: 10;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: nowrap;
  flex-direction: row;
  align-content: flex-start;

  .headerTitlel {
    width: 30%;
    display: flex;
    justify-content: flex-start;
    align-items: flex-start;
    flex-wrap: nowrap;
    height: 100%;
    flex-direction: row;
    align-content: flex-start;
    z-index: 100;

    span {
      font-size: 16px;
      font-family: PingFang SC-Bold, PingFang SC;
      font-weight: bold;
      color: #3FD1FF;
      margin-left: 16px;
      margin-top: 40px;
    }
  }

  .headerTitler {
    width: calc(30% - 20px);
    position: relative;
    height: 100%;
    display: flex;
    justify-content: flex-start;
    align-items: flex-start;
    flex-wrap: nowrap;
    flex-direction: row;
    align-content: flex-start;
    margin-right: 20px;
    margin-left: 20px;
    z-index: 100;

    span {
      font-size: 16px;
      font-family: PingFang SC, PingFang SC;
      font-weight: 500;
      margin-top: 80px;
      background: linear-gradient(180deg, #AEECFF 0%, #68D2FF 100%);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
    }

    .dateTime {
      display: flex;
      justify-content: flex-end;
      align-items: center;
      flex-wrap: nowrap;
      flex-direction: row;
      align-content: flex-start;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }

    .tabs {
      display: flex;
      position: absolute;
      top: 70px;
      right: 0;
      font-size: 16px;
      color: #fff;

      .tabItem {
        background: url("./assets/butbg.png") no-repeat;
        background-size: cover;
        padding: 7px 20px;
        cursor: pointer;
        margin-right: 10px;
      }
      .tabItem2 {
        background: url("./assets/butbg.png") no-repeat;
        background-size: cover;
        padding: 7px 20px;
        cursor: pointer;
        opacity: 0.5;
      }
    }
  }

  .headerTitle {
    position: relative;
    z-index: 100;
    height: 50px;
    width: 50%;
    display: flex;
    margin-top: 20px;
    justify-content: center;
    align-items: center;
    flex-wrap: nowrap;
    flex-direction: row;
    align-content: flex-start;
    span {
      font-size: 38px;
      font-family: YouSheBiaoTiHei, YouSheBiaoTiHei;
      font-weight: 400;
      line-height: 45px;
      //text-shadow: 0px 4px 6px rgba(0,0,0,0.25);
      background: linear-gradient(180deg, #F2FCFF 0%, #47C8FF 100%);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
    }
  }
}

</style>
